package com.cn.crmsystem.controller.approveController;

import com.cn.crmsystem.pojo.*;
import com.cn.crmsystem.service.approveService.LeaveService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@Api(value = "请假api",tags = "请假API")
public class LeaveController {
	@Autowired LeaveService leaveService;
//查询
@RequestMapping(value = "/SelectLeave",name = "请假查询",method = RequestMethod.POST)
@ApiOperation(value = "查询请假",notes = "查询",httpMethod = "POST", response = String.class)
@ApiImplicitParams({
		@ApiImplicitParam(name = "userid",value = "用户id",paramType = "query",dataType = "Integer",required = false),
		@ApiImplicitParam(name = "method",value = "我发出的还是我审核",paramType = "query",dataType = "String",required = false)
})
@ResponseBody
public  ResultJson SelectLeave(@RequestParam(name = "userid") Integer userid,
								@RequestParam(name = "method") String method){
		ResultJson resultJson=new ResultJson();
	leaveService.SelectMyLeave(userid,method);
		return resultJson;
	}
	//修改
	@RequestMapping(value = "/LeaveUpdate",name = "修改请假",method = RequestMethod.POST)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "appid",value = "审核id",paramType = "query",dataType = "Integer",required = false),
			@ApiImplicitParam(name = "state",value = "状态",paramType = "query",dataType = "Integer",required = false)
	})
	@ApiOperation(value = "修改请假",notes = "更新",httpMethod = "POST", response = String.class)
	@ResponseBody
	public  ResultJson LeaveUpdate(@RequestParam(name = "appid") Integer appid,
								   @RequestParam(name = "state") Integer state){
		ResultJson resultJson=new ResultJson();
		leaveService.UpdateLeave(appid,state);
		return  resultJson;
	}
	//删除
	@RequestMapping(value = "/LeaveDelete",name = "删除请假",method = RequestMethod.POST)
	@ApiOperation(value = "删除请假",notes = "更改deleteid",httpMethod = "POST", response = String.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "appid",value = "审核id",paramType = "query",dataType = "Integer",required = false)
	})
	@ResponseBody
	public  ResultJson DeleteLeave(@RequestParam(name = "appid") Integer appid){
		ResultJson resultJson=new ResultJson();
		leaveService.DeleteLeave(appid);
		return  resultJson;
	}
	//查询审核人
	@RequestMapping(value = "/selectLeaveLeader",name = "查询审核人请假",method = RequestMethod.POST)
	@ApiOperation(value = "查询审核人",notes = "查询",httpMethod = "POST", response = String.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userid",value = "用户id",paramType = "query",dataType = "Integer",required = false)
	})
	@ResponseBody
	public  ResultJson selectLeaveLeader (@RequestParam(name = "userid")  Integer userid){
		ResultJson resultJson=new ResultJson();
		leaveService.selectLeader(userid);
		return  resultJson;
	}
	//增加
	@RequestMapping(value = "/InsertLeave",name = "请假增加",method = RequestMethod.POST)
	@ApiOperation(value = "请假增加",notes = "插入",httpMethod = "POST", response = String.class)
	@ResponseBody
	public  ResultJson InsertLeave (@RequestBody
									 @ApiParam(name ="新建请假",value = "增加") Approve AP){
		ResultJson resultJson=new ResultJson();
	Integer leaderid=AP.getLeader_Id();
	Leave leave=AP.getLeave();
		leaveService.LeaveInsert(leave,leaderid);
		return  resultJson;
	}
	//条件查询
	@RequestMapping(value = "/SelectConditionLeave",name = "条件查询请假",method = RequestMethod.POST)
	@ApiOperation(value = "请假条件查询",notes = "条件查询",httpMethod = "POST", response = String.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userid",value = "用户id",paramType = "query",dataType = "Integer",required = false),
			@ApiImplicitParam(name = "state",value = "审核状态",paramType = "query",dataType = "Integer",required = false),
			@ApiImplicitParam(name = "method",value = "我发出的还是我审核",paramType = "query",dataType = "String",required = false)
	})
	@ResponseBody
	public  ResultJson SelectConditionLeave(@RequestParam(name = "userid") Integer userid,
									@RequestParam(name = "state") String method,
									@RequestParam(name = "method") String state ){
		ResultJson resultJson=new ResultJson();
		leaveService.SelectConditionLeave(userid,method,state);
		return resultJson;
	}
}
